//package com.ct.boot.launch.config;
//
//import com.atomikos.icatch.jta.UserTransactionImp;
//import com.atomikos.icatch.jta.UserTransactionManager;
//import org.apache.commons.configuration2.plist.PropertyListParserConstants;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.ComponentScan;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
//import org.springframework.orm.jpa.JpaVendorAdapter;
//import org.springframework.orm.jpa.vendor.Database;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.jta.JtaTransactionManager;
//
//import javax.transaction.SystemException;
//import javax.transaction.TransactionManager;
//import javax.transaction.UserTransaction;
//
///**
// * @Auther: Charles chen
// * @Date: 2020/7/19 11:57
// * @Description:
// */
//@Configuration
//@ComponentScan
//@EnableTransactionManagement
//public class JPAAtomikosTransactionManagement {
//    @Bean
//    public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
//        return new PropertySourcesPlaceholderConfigurer();
//    }
//
//    //设置Jpa特性
//    @Bean
//    public JpaVendorAdapter jpaVendorAdapter(){
//        HibernateJpaVendorAdapter hibernateJpaVendorAdapter=new HibernateJpaVendorAdapter();
//        //显示sql
//        hibernateJpaVendorAdapter.setShowSql(true);
//        //自动更新表
//        hibernateJpaVendorAdapter.setGenerateDdl(true);
//        //数据库类型
//        hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
//        return hibernateJpaVendorAdapter;
//    }
//    @Bean(name = "userTransaction")
//    public UserTransaction userTransaction() throws SystemException {
//        UserTransactionImp userTransactionImp=new UserTransactionImp();
//        userTransactionImp.setTransactionTimeout(1000);
//        return userTransactionImp;
//    }
//
//    @Bean(name = "atomikosTransactionManager",initMethod = "init",destroyMethod = "close")
//    public TransactionManager atomikosTransactionManager(){
//        UserTransactionManager userTransactionManager=new UserTransactionManager();
//        userTransactionManager.setForceShutdown(false);
//        AtomikosJtaPlatform.transactionManager=userTransactionManager;
//        return userTransactionManager;
//    }
//    @Bean(name = "transactionManager")
//    public PlatformTransactionManager transactionManager() throws SystemException {
//        UserTransaction userTransaction=userTransaction();
//        AtomikosJtaPlatform.userTransaction=userTransaction;
//        TransactionManager atomikosTransactionManger=atomikosTransactionManager();
//        return new JtaTransactionManager(userTransaction,atomikosTransactionManger);
//    }
//}
